package hxy.dragon.location_record;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import java.text.SimpleDateFormat;
import java.util.List;

import hxy.dragon.location_record.tencent.LocationModel;

public class LocationAdapter extends androidx.recyclerview.widget.RecyclerView.Adapter<LocationAdapter.ViewHolder> {
    private Context mContext;
    List<hxy.dragon.location_record.tencent.LocationModel> locationModelList;

    static class ViewHolder extends androidx.recyclerview.widget.RecyclerView.ViewHolder {
        android.widget.LinearLayout cardView;  //日记视图
        android.widget.TextView item_date;  //日期
        android.widget.TextView item_datetime;  //日期
        android.widget.ImageView item_weather;  //天气
        android.widget.TextView itemAddress;  //标题


        public ViewHolder(@androidx.annotation.NonNull android.view.View view) {
            super(view);
            cardView = (android.widget.LinearLayout) view;
            item_date = view.findViewById(R.id.simple_item_date);
            item_datetime = view.findViewById(R.id.simple_item_datetime);
            item_weather = view.findViewById(R.id.simple_item_weather);
            itemAddress = view.findViewById(R.id.simple_item_address);

        }
    }

    public LocationAdapter(Context mContext, List<LocationModel> list) {
        this.mContext = mContext;
        this.locationModelList = list;
    }

    @androidx.annotation.NonNull
    @Override
    public LocationAdapter.ViewHolder onCreateViewHolder(@androidx.annotation.NonNull android.view.ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        //绑定事件
        View view = LayoutInflater.from(mContext).inflate(R.layout.simple_history_item, parent, false);

        final ViewHolder viewHolder = new ViewHolder(view);


        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@androidx.annotation.NonNull LocationAdapter.ViewHolder holder, int position) {
        LocationModel locationModel = locationModelList.get(position);


        holder.itemAddress.setText(locationModel.getAddress());
        holder.item_date.setText(locationModel.getName());
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long time = locationModel.getTime();
        String date = df.format(time);
        holder.item_datetime.setText(date);

    }

    @Override
    public int getItemCount() {
        return locationModelList.size();
    }
}
